﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CustomizedCommandXMLChecker.CUICustomizedCommandXMLCheckerCmd
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.ObjectModel;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.CustomizedCommandXMLChecker;

public class CUICustomizedCommandXMLCheckerCmd : TxButtonCommand
{
  protected TxCommandTypeFilterEnabler m_enabler;
  private CUICustomizedCommandXMLCheckerForm m_checkerForm;

  public CUICustomizedCommandXMLCheckerCmd()
  {
    this.m_enabler = new TxCommandTypeFilterEnabler((ITxTypeFilter) new TxTypeFilter(typeof (TxRobot)), true);
  }

  public virtual string Category => CapCustomizedCommandXMLCheckerStringTable.CMD_CATEGORY;

  public virtual string Name => CapCustomizedCommandXMLCheckerStringTable.CMD_NAME;

  public virtual string Tooltip => CapCustomizedCommandXMLCheckerStringTable.CMD_TOOLTIP;

  public virtual string Bitmap => "CustomizedCommandXMLChecker.CustomizedCommandXMLChecker.bmp";

  public virtual string LargeBitmap
  {
    get => "CustomizedCommandXMLChecker.CustomizedCommandXMLCheckerLarge.png";
  }

  public virtual string MediumBitmap
  {
    get => "CustomizedCommandXMLChecker.CustomizedCommandXMLCheckerMedium.png";
  }

  public virtual string Description => CapCustomizedCommandXMLCheckerStringTable.CMD_DESCRIPTION;

  public virtual ITxCommandEnabler CommandEnabler => (ITxCommandEnabler) this.m_enabler;

  public virtual bool Licensed => TxCommandLicenser.CustomizedUILicense;

  public virtual ITxImage Image => (ITxImage) TxImageManager.GetImageByKey("XmlChecker");

  public virtual void Execute(object cmdParams)
  {
    TxRobot robot = (TxRobot) null;
    if (cmdParams is TxRobot)
    {
      robot = cmdParams as TxRobot;
    }
    else
    {
      TxObjectList items = TxApplication.ActiveSelection.GetItems();
      if (((Collection<ITxObject>) items)[0] is TxRobot)
        robot = ((Collection<ITxObject>) items)[0] as TxRobot;
    }
    if (!TxRobot.op_Inequality(robot, (ITxObject) null))
      return;
    this.m_checkerForm = new CUICustomizedCommandXMLCheckerForm(robot);
    TxApplication.ApplicationEvents.Exiting += new TxApplication_ExitingEventHandler(this.ApplicationEvents_Exiting);
    ((Form) this.m_checkerForm).FormClosed += new FormClosedEventHandler(this.form_FormClosed);
    ((Control) this.m_checkerForm).Show();
    this.m_checkerForm.Check();
  }

  private void ApplicationEvents_Exiting(object sender, TxApplication_ExitingEventArgs args)
  {
    if (this.m_checkerForm == null)
      return;
    ((Form) this.m_checkerForm).Close();
  }

  private void form_FormClosed(object sender, FormClosedEventArgs e)
  {
    TxApplication.ApplicationEvents.Exiting -= new TxApplication_ExitingEventHandler(this.ApplicationEvents_Exiting);
  }
}
